﻿// Copyright (c)  YISH. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using System.Collections.Generic;

namespace NSQL.Resource
{
    public class TableInfo : ITableInfo
    {
        private readonly List<IColumnInfo> _columns = new List<IColumnInfo>();
        public IDatabaseInfo Database => Schema?.DatabaseInfo;
        public ISchemaInfo Schema { get; set; }
        public int Id { get; set; }
        public Identifier Name { get; set; }
        public string Expr { get; set; }
        public Identifier Alias { get; set; }
        public IReadOnlyList<IColumnInfo> Columns => _columns;
        public void Add(IColumnInfo columnInfo) => _columns.Add(columnInfo);

        public void Add(ColumnInfo columnInfo)
        {
            columnInfo.Table = this;
            _columns.Add(columnInfo);
        }
        public void AddRange(params ColumnInfo[] columnsInfo)
        {
            foreach (var column in columnsInfo)
            {
                Add(column);
            }
        }
    }
}